package com.zmn.plat.business.impl.product.tariff.tariffproductitem3;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.business.interfaces.product.tariff.tariffproductitem3.TariffProductItem3BService;
import com.zmn.plat.model.entity.product.tariff.tariffproductitem3.TariffProductItem3;
import com.zmn.plat.services.interfaces.product.tariff.tariffproductitem3.TariffProductItem3Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @version v1.0
 * @author: shenxiangzhong
 * @since: 2021/11/26 15:42
 */
public class TariffProductItem3BServiceImpl implements TariffProductItem3BService {

    private Logger logger = LoggerFactory.getLogger(TariffProductItem3BServiceImpl.class);
    @Resource
    private TariffProductItem3Service tariffProductItem3Service;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<Integer> add(TariffProductItem3 tariffProductItem,String operator) {
        try {
            Date now = new Date();
            tariffProductItem.setUpdater(operator);
            tariffProductItem.setUpdateTime(now);
            if (NumberUtil.isNullOrZero(tariffProductItem.getRelateId())) {
                tariffProductItem.setCreater(operator);
                tariffProductItem.setCreateTime(now);
                tariffProductItem3Service.insert(tariffProductItem);
            } else {
                tariffProductItem.setUpdater(operator);
                tariffProductItem.setUpdateTime(now);
                tariffProductItem3Service.updateByKey(tariffProductItem);
            }
            return ResponseDTO.success(tariffProductItem.getRelateId(),"操作成功！");
        } catch (Exception e) {
            logger.error("新增/修改失败,Exception{},msg{}", e, e.getMessage());
            return ResponseDTO.fail("操作失败！");
        }
    }
}
